﻿using System;
using System.Collections.Generic;
using BooksOnline.Models.Entities;
using BooksOnline.Repositories.Base;
using NHibernate.Criterion;

namespace BooksOnline.Repositories
{
    public class RecommendationRepository : RepositoryBase<Recommendation>
    {
        public IList<Recommendation> ByBookId(Guid id)
        {
            return
                DetachedCriteria
                    .For<Recommendation>()
                    .CreateAlias("Book", "book")
                    .Add(Restrictions.Eq("book.Id", id))
                    .GetExecutableCriteria(CurrentSession)
                    .List<Recommendation>();
        }

        public IList<Recommendation> ByCustomerId(Guid id)
        {
            return
                DetachedCriteria
                    .For<Recommendation>()
                    .CreateAlias("Customer", "cust")
                    .Add(Restrictions.Eq("cust.Id", id))
                    .GetExecutableCriteria(CurrentSession)
                    .List<Recommendation>();
        }
    }
}